package com.entity;

import com.util.GameUtil;
import com.view.GameFrame;

import java.awt.*;

/**
 * @author: Combo
 * @time: 2021/1/4 11:11
 * @description: 人物
 */
public class Person {

    private Image image;    // 当前显示的图片

    private Image[] images; // 人物所有图片

    public static final int WIDTH = 120;

    public static final int HEIGHT = 120;

    private Integer x; // 初始坐标

    private Integer y; // 初始坐标

    private Integer index; // 图片切换

    private Integer score; // 得分

    private Integer distance; // 距离

    public Person() {
        init();
        image = images[0];
        x = 90;
        y = 580;
        index = 0;
        score = 0;
        distance = 0;
    }

    /**
     * 人物下落
     */
    public void drop(){
        y += 5;
        // 防止穿模
        if (y >= 580){
            y = 580;
        }
    }

    /**
     * 人物移动
     */
    public void step(){
        image = images[index++ / 3 % images.length];
    }

    /**
     * 绘制人物
     * @param g
     */
    public void paintPerson(Graphics g){
        g.drawImage(image, x, y, WIDTH, HEIGHT, null);
    }

    /**
     * 人物是否越界
     * @return
     */
    public boolean outOfBounds(){
        return this.x >= GameFrame.WIDTH || this.x <= -WIDTH;
    }

    /**
     * 初始化人物
     */
    private void init() {
        images = new Image[9];
        for (int i = 0; i < images.length; i++){
            images[i] = GameUtil.getImage("images/person/" + (i+1) + ".png");
        }
    }

    public Image getImage() {
        return image;
    }

    public void setImage(Image image) {
        this.image = image;
    }

    public Image[] getImages() {
        return images;
    }

    public void setImages(Image[] images) {
        this.images = images;
    }

    public static int getWIDTH() {
        return WIDTH;
    }

    public static int getHEIGHT() {
        return HEIGHT;
    }

    public Integer getX() {
        return x;
    }

    public void setX(Integer x) {
        this.x = x;
    }

    public Integer getY() {
        return y;
    }

    public void setY(Integer y) {
        this.y = y;
    }

    public Integer getIndex() {
        return index;
    }

    public void setIndex(Integer index) {
        this.index = index;
    }

    public Integer getScore() {
        return score;
    }

    public void setScore(Integer score) {
        this.score = score;
    }

    public Integer getDistance() {
        return distance;
    }

    public void setDistance(Integer distance) {
        this.distance = distance;
    }
}
